from machine import SPI, Pin, I2C

from ST7735 import TFT, bitSwap

import time
import framebuf
import aht10

addr = 0x38
i2c = I2C(0, scl=Pin(5), sda=Pin(4), freq = 1_000_000)
def main():
    aht = aht10.AHT10(i2c,0,addr)
    spi = SPI(1, baudrate=40000000, polarity=0, phase=0,sck=Pin(2), mosi=Pin(3))
    tft=TFT(spi,'/combined.bin',6,10,7,160,80)
    tft.init_7735(tft.REDTAB80x160)
    tft.fill(tft.BLACK)
    time.sleep(1)
    while True:
        shidu = aht.humidity()#湿度
        wendu = aht.temperature()#温度
        tft.buffer.fill(0)
        tft.text((1,1),str("温度：%.2f" %(wendu)), bitSwap(TFT.RED),(2,2))
        tft.text((1,30),str("湿度：%.2f" %(shidu)), bitSwap(TFT.GREEN),(2,2))
        # tft.text((1,60),str(time.strftime('%Y.%m.%d',time.localtime(time.time()))), bitSwap(TFT.GREEN),(2,2))
        buffer = tft.buffer
        tft.image(0,0,160,80,buffer)
        time.sleep(5)
if __name__ == "__main__":
    main()
    
